<template>
	<view>
		<view class="header-title">基本信息</view>
		<view class="main">
			<view class="main-item flex" @tap="editName">
				<text>用户名</text>
				<view class="item-right flex">
					<input :value="userInfo.name" placeholder-class="placeholder" @input="getName" disabled="true" />
					<image :src="imgurl+'youjiantou.png'"></image>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="main-item flex" @tap="editPhone">
				<text>手机号码</text>
				<view class="item-right flex">
					<input :value="userInfo.call" placeholder-class="placeholder" @input="getPhone" disabled="true" />
					<image :src="imgurl+'youjiantou.png'"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from "../../../App.vue"
	import api from "@/common/api.js"
	export default {
		data() {
			return {
				imgurl: "",
				name: "",
				phone: "",
				jifen: '',
				userInfo: {}
			};
		},
		methods: {
			editName() {
				uni.navigateTo({
					url: '../editMessages/editMessages?id=' + this.userInfo.id
				})
			},
			editPhone() {
				uni.navigateTo({
					url: '../editPhone/editPhone?id=' + this.userInfo.id
				})
			},
			getName(e) {
				this.name = e.detail.value
			},
			getPhone(e) {
				this.phone = e.detail.value
			},
			getUserInfo(id) {
				api.look({id: id, api: 'wenfind', table: '1'}).then(res => {
					if(res.code === 200) {
						this.userInfo = res.date[0]
						console.log(this.userInfo, 'USER')
					}
				}).catch(err => {
					console.log(err)
				})
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad() {
			this.imgurl = app.globalData.imgurls
			uni.getStorage({
				key: 'message',
				success: (res) => {
					this.userid = res.data[0].id
					this.getUserInfo(res.data[0].id)
				},
			})
		}
	}
</script>

<style lang="scss">
	page {
		background: #F0F0F0;
		font-family: PingFang SC;
		font-weight: 500;
	}

	.header-title {
		width: 100%;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 30rpx;
		color: #999;
		padding-left: 30rpx;
	}

	.placeholder {
		color: #333;
		font-size: 36rpx;
	}

	.main {
		width: 100%;
		background: #fff;
	}

	.other {
		border-bottom: none;
	}

	.main-item {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		border-bottom: 1rpx solid #dfdfdf;
		margin: 0 auto;
		justify-content: space-between;
		font-size: 36rpx;
		color: #333;

		text {}

		.item-right {
			input {
				text-align: right;
			}

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}
</style>
